package com.umfb.bootstrap.controller.web;
import com.alibaba.dubbo.config.annotation.Reference;
import com.umfb.demo.entity.Player;
import com.umfb.demo.entity.User;
import com.umfb.demo.service.IJedisClient;
import com.umfb.demo.service.IMongoService;
import com.umfb.demo.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * Created by gzheng on 17-11-17.
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Reference
    IJedisClient jedisClient;

    @Reference
    IMongoService mongoService;

    @Reference
    IUserService iUserService;
    @RequestMapping(value = "/login")
    public ModelAndView userLogin(@RequestParam(value = "userName", required = true) String userName,
                                  @RequestParam(value = "password", required = true) String password){
        int i = 5;
        jedisClient.set(userName,password,i);
        User user = new User();
        user.setEmail(userName);
        user.setPhone("13633409127");
        user.setPassword(password);
        iUserService.saveOrUpdate(user);

        Player player = new Player();
        player.setCreateAt(new Date());
        player.setIdCode("140427198804188037");
        player.setPlayerName(userName);
        player.setUserId(password);
       mongoService.addDemoPlayer(player);

        ModelAndView mv = new ModelAndView();
        mv.setViewName("say");
        return mv;
    }
}
